package com.jl.resolver;

import org.springframework.core.MethodParameter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor;

import java.util.List;

/**
 * 统一按 @ResponseBody 方式处理
 */
public class ContractRequestResponseBodyMethodProcessor extends RequestResponseBodyMethodProcessor implements DefaultMethodArgumentResolverSupportable {

    public ContractRequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters) {
        super(converters);
    }

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return DefaultMethodArgumentResolverSupportable.super.supportsParameter(parameter, super::supportsParameter);
    }

    /**
     * 所有方法使用这个@ResponseBody方式
     */
    @Override
    public boolean supportsReturnType(MethodParameter returnType) {
        //放行swagger
        if ("swaggerResources".equals(returnType.getExecutable().getName())
                || "getDocumentation".equals(returnType.getExecutable().getName())) {
            return false;
        }
        return true;
    }
}
